$(document).ready(function(){	
	$("#old_password").focus(function(){
		$("#old_password").css("background", "url('" + contextPath + "/image/bg_text_blank.png')");
	});
	$("#old_password").blur(function(){
		if ($("#old_password").val() == "") {
			$("#old_password").css("background", "url('" + contextPath + "/image/bg_text_old_password.png')");
		}
	});
	

	$("#new_password").focus(function(){
		$("#new_password").css("background", "url('" + contextPath + "/image/bg_text_blank.png')");
	});
	$("#new_password").blur(function(){
		if ($("#new_password").val() == "") {
			$("#new_password").css("background", "url('" + contextPath + "/image/bg_text_new_password.png')");
		}
	});
	
	$("#confirm_new_password").focus(function(){
		$("#confirm_new_password").css("background", "url('" + contextPath + "/image/bg_text_blank.png')");
	});
	$("#confirm_new_password").blur(function(){
		if ($("#confirm_new_password").val() == "") {
			$("#confirm_new_password").css("background", "url('" + contextPath + "/image/bg_text_confirm_new_password.png')");
		}
	});
	
	$("#old_password").focus();
	addFadeEffect();
});

function modifyPassword() {
	var newPassword = $("#new_password").val();
	var confirmNewPassword = $("#confirm_new_password").val();
	var password = $("#old_password").val();
	var params;

	
	var pattern = /[a-zA-Z0-9]{4,20}/;
	if (password == "" || !pattern.test(password)) {
		$("#error_message_modify_password").html("密码错误<br/>");
		$("#old_password").css("background", "#fbe2e2");
		return;
	} else {
		$("#error_message_modify_password").html("");
		$("#old_password").css("background", "url('" + contextPath + "/image/bg_text_blank.png')");
	}
	
	if (newPassword == "" || !pattern.test(newPassword)) {
		$("#error_message_modify_password").html("新密码错误<br/>");
		$("#new_password").css("background", "#fbe2e2");
		return;
	} else {
		$("#error_message_modify_password").html("");
		$("#new_password").css("background", "url('" + contextPath + "/image/bg_text_blank.png')");
	}
	
	if (confirmNewPassword != newPassword) {
		$("#error_message_modify_password").html("重复新密码错误<br/>");
		$("#confirm_new_password").css("background", "#fbe2e2");
		return;
	} else {
		$("#error_message_modify_password").html("");
		$("#confirm_new_password").css("background", "url('" + contextPath + "/image/bg_text_blank.png')");
	}
	
	params = {
			request_method:"modify_password",
			new_password:newPassword,
			old_password:password
	};
	
	$.post("customer_json_servlet", params, function(ret){
		if (ret.code == 0) {
			cancelModifyPasswordDlg();
		} else {
			$("#error_message_modify_password").html(ret.message);
		}
	}, "json");
}